package com.example.ymm.modules1.service.impl.ms;

import com.baomidou.dynamic.datasource.annotation.Slave;
import com.example.ymm.base.BaseServiceImpl;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.entity.ms.DEmployee;
import com.example.ymm.modules1.mapper.ms.DEmployeeMapper;
import com.example.ymm.modules1.query.ms.DEmployeeQueryCriteria;
import com.example.ymm.modules1.service.ms.DEmployeeService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
// @Transactional
@Slf4j
@Slave
public class DEmployeeServiceImpl extends BaseServiceImpl<DEmployeeMapper, DEmployee> implements DEmployeeService {

    @Override
    public TableList<DEmployee> list(DEmployeeQueryCriteria criteria, YmPageDto pageDto) {
        getPage(pageDto);
        List<DEmployee> arrs = baseMapper.userViewList(criteria);
        PageInfo<DEmployee> pageInfo = new PageInfo<>(arrs);
        TableList<DEmployee> tableList = new TableList(pageInfo);
        return tableList;
    }

    public List<DEmployee> queryAll(DEmployeeQueryCriteria criteria) {

        List<DEmployee> result = baseMapper.userViewList(criteria);
        return result;
    }


    @Override
    public String getTidByName(String name) {
        DEmployeeQueryCriteria criteria = new DEmployeeQueryCriteria();
        criteria.setName(name);
        List<DEmployee> queryAll = queryAll(criteria);
        if (queryAll.size() > 0) {
            return queryAll.get(0).getTid();
        }
        return null;
    }

    @Override
    public DEmployee getUserInfo(String userName) {
        DEmployeeQueryCriteria criteria = new DEmployeeQueryCriteria();
        criteria.setName(userName);
        List<DEmployee> queryAll = queryAll(criteria);
        if (queryAll.size() > 0) {
            return queryAll.get(0);
        }
        return null;
    }
}
